{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "PusSiFPNP6D-"
      },
      "source": [
        "## **Step 1: Please select a GPU runtime**\n",
        "\n",
        "![](https://i.imgur.com/RUIixAQ.png) ![image.png](https://i.imgur.com/zKc74pP.png)\n",
        "\n",
        "## **Step 2: Install TVM by running the following block.**\n",
        "\n",
        "We have pre-compiled a tvm build for your convenience.\n",
        "\n",
        "![](https://i.imgur.com/k9U5WCB.png)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "wEdaUq8fQci9",
        "outputId": "24b83bae-0708-4112-e5b8-92914b48bc94"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Requirement already satisfied: wget in /usr/local/lib/python3.7/dist-packages (3.2)\n",
            "Your python version is  Python 3.7.12\n",
            "\n",
            "Successfully installed TVM!\n"
          ]
        }
      ],
      "source": [
        "# Let's first install TVM!\n",
        "# This TVM git tag is: 3b8715df7ea9263b71e30888f1aa112bd8cfcfdc\n",
        "# which is prior to our 1st detected bug.\n",
        "!pip install wget\n",
        "import os\n",
        "import wget\n",
        "\n",
        "# Your Python should be Python 3.7\n",
        "pyversion = os.popen('python3 --version').read()\n",
        "print('Your python version is ', pyversion)\n",
        "\n",
        "def install_tvm(pattern):\n",
        "    return wget.download(\n",
        "        'https://github.com/ise-uiuc/tzer/releases/download/tvm-0.8.dev1040/' +\n",
        "        'tlcpack_nightly-0.8.dev1040+g3b8715df7-' + pattern +\n",
        "        'm-manylinux_2_17_x86_64.manylinux2014_x86_64.whl')\n",
        "\n",
        "whl_name = None\n",
        "if '3.8' in pyversion:\n",
        "    # TVM for Python 3.8\n",
        "    whl_name = install_tvm(\"cp38-cp38\")\n",
        "elif '3.7' in pyversion: \n",
        "    # TVM for Python 3.7\n",
        "    whl_name = install_tvm(\"cp37-cp37m\")\n",
        "elif '3.6' in pyversion:\n",
        "    # TVM for Python 3.6\n",
        "    whl_name = install_tvm(\"cp36-cp36m\")\n",
        "else:\n",
        "    print('Please make sure you have Python 3.6,7,8. Actually, 3.7+ is recommended.')\n",
        "\n",
        "if whl_name:\n",
        "    os.system('python3 -m pip install ' + whl_name)\n",
        "    import tvm\n",
        "    print('Successfully installed TVM!')\n",
        "else:\n",
        "    print('Failed to install tvm...')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "kfIe3cR_ZvpA"
      },
      "source": [
        "## **Step 3: Click the bottoms to run bugs!**\n",
        "\n",
        "![](https://i.imgur.com/OG7YPlK.png)\n",
        "\n",
        "## Notes: Bug symptom\n",
        "\n",
        "For bugs whose symptom is crash (e.g., Bug 1), you will see:\n",
        "\n",
        "![](https://i.imgur.com/iRuFd1H.png)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Svd2fy_uJLsK"
      },
      "source": [
        "## Bug 1"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "YkR-2Si1JYgJ"
      },
      "outputs": [],
      "source": [
        "# Crash. You will see \"Your session crashed for an unknown reason\" after running this bug.\n",
        "import tvm\n",
        "from tvm import tir\n",
        "\n",
        "v = tir.Cast('bool', tvm.runtime.convert(\"a\"))\n",
        "body = tir.stmt.While(v, body=tir.Evaluate(tir.const(0)))\n",
        "func = tir.PrimFunc(params={}, body=body)\n",
        "mod = tvm.lower(func)\n",
        "nopt_mod = tvm.build(mod)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "203y3y9AIIvh"
      },
      "source": [
        "## Bug 2 & Bug 3"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "70XpGgkaIsrf"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "from tvm import ir, tir\n",
        "\n",
        "a = tir.Var(\"a\", \"int32\")\n",
        "b = tir.Var(\"b\", \"handle\")\n",
        "iter_var = tir.IterVar(ir.Range(0,1 ), a, 1)\n",
        "buffer = tir.buffer.decl_buffer((1,))\n",
        "buffer_map = {b: buffer}\n",
        "store = tir.Store(buffer.data, tir.const(1), tir.const(1))\n",
        "attr_stmt = tir.AttrStmt(iter_var, \"coproc_uop_scope\", tir.const(1), store)\n",
        "f = tir.PrimFunc({a, b}, body=attr_stmt, buffer_map=buffer_map)\n",
        "mod = tvm.lower(f)\n",
        "tvm.build(mod)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "c0qt8JwgIVYg"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "from tvm import ir, tir\n",
        "\n",
        "a = tir.Var(\"a\", \"int32\")\n",
        "b = tir.Var(\"b\", \"handle\")\n",
        "iter_var = tir.IterVar(ir.Range(0,1 ), a, 1)\n",
        "buffer = tir.buffer.decl_buffer((1,))\n",
        "buffer_map = {b: buffer}\n",
        "store = tir.Store(buffer.data, tir.const(1), tir.const(1))\n",
        "attr_stmt = tir.AttrStmt(iter_var, \"compute_scope\", tir.const(1), store)\n",
        "f = tir.PrimFunc({a, b}, body=attr_stmt, buffer_map=buffer_map)\n",
        "mod = tvm.lower(f)\n",
        "tvm.build(mod)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "u5yp0WIyF3E-"
      },
      "source": [
        "## Bug 4"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 663
        },
        "id": "tATNz91nHrF1",
        "outputId": "d2b9f19d-60a5-498e-98fb-83300bf89c11"
      },
      "outputs": [
        {
          "ename": "AttributeError",
          "evalue": "ignored",
          "output_type": "error",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
            "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/tvm/runtime/object.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m     62\u001b[0m         \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 63\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0m_ffi_node_api\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mNodeGetAttr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     64\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0mAttributeError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./packed_func.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.PackedFuncBase.__call__\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./packed_func.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.FuncCall\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./packed_func.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.FuncCall3\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./base.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.CALL\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;31mAttributeError\u001b[0m: Traceback (most recent call last):\n  3: TVMFuncCall\n  2: _ZNSt17_Function_handlerI\n  1: tvm::NodeGetAttr(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)\n  0: tvm::ReflectionVTable::GetAttr(tvm::runtime::Object*, tvm::runtime::String const&) const\n  File \"/workspace/tvm/src/node/reflection.cc\", line 110\nAttributeError: tir.Shuffle object has no attributed dtype",
            "\nDuring handling of the above exception, another exception occurred:\n",
            "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-1-08dc90db8141>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mtvm\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtvm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtir\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mShuffle\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/tvm/runtime/object.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m     63\u001b[0m             \u001b[0;32mreturn\u001b[0m \u001b[0m_ffi_node_api\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mNodeGetAttr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     64\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0mAttributeError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 65\u001b[0;31m             \u001b[0;32mraise\u001b[0m \u001b[0mAttributeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"%s has no attribute %s\"\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     66\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     67\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m__hash__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;31mAttributeError\u001b[0m: <class 'tvm.tir.expr.Shuffle'> has no attribute dtype"
          ]
        }
      ],
      "source": [
        "import tvm\n",
        "print(tvm.tir.Shuffle([1],[1]).dtype)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6uFxVgL1JiKC"
      },
      "source": [
        "## Bug 5 & Bug 6 & Bug 7 & Bug 8"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "MBg7B_EvJteF"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "\n",
        "analyzer = tvm.arith.Analyzer()\n",
        "analyzer.rewrite_simplify(tvm.tir.Div(tvm.tir.Ramp(1,1,2), tvm.tir.Broadcast(0, 2)))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "SjSPqXfQKCXl"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "\n",
        "analyzer = tvm.arith.Analyzer()\n",
        "analyzer.rewrite_simplify(tvm.tir.Mod(tvm.tir.Ramp(1,1,2), tvm.tir.Broadcast(0, 2)))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "kECN8UW8KFaV"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "\n",
        "analyzer = tvm.arith.Analyzer()\n",
        "analyzer.rewrite_simplify(tvm.tir.FloorDiv(tvm.tir.Ramp(1,1,2), tvm.tir.Broadcast(0, 2)))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "Iy58n1scKLfo"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "\n",
        "analyzer = tvm.arith.Analyzer()\n",
        "analyzer.rewrite_simplify(tvm.tir.FloorMod(tvm.tir.Ramp(1,1,2), tvm.tir.Broadcast(0, 2)))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-HTdNvvPPmIC"
      },
      "source": [
        "## Bug 9"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 197
        },
        "id": "cwWByEwKPogb",
        "outputId": "032477f2-82a7-42a4-b181-666c94083df6"
      },
      "outputs": [
        {
          "ename": "AssertionError",
          "evalue": "ignored",
          "output_type": "error",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mAssertionError\u001b[0m                            Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-1-f39163c75739>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m     22\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     23\u001b[0m \u001b[0;32massert\u001b[0m \u001b[0mold_mod\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastext\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mmod\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastext\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 24\u001b[0;31m \u001b[0;32massert\u001b[0m \u001b[0mold_mod\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastext\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mnew_mod\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastext\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;31mAssertionError\u001b[0m: "
          ]
        }
      ],
      "source": [
        "import tvm\n",
        "\n",
        "from tvm import relay\n",
        "from tvm.relay.testing import create_workload\n",
        "\n",
        "simple_net = relay.nn.conv2d(\n",
        "    data=relay.var(\"data\", relay.TensorType((1, 3, 224, 224), \"float32\")),\n",
        "    weight=relay.var(\"weight\"),\n",
        "    kernel_size=(5, 5),\n",
        "    channels=3,\n",
        "    padding=(1, 1),\n",
        ")\n",
        "simple_net = relay.Function(relay.analysis.free_vars(simple_net), simple_net)\n",
        "mod, _ = create_workload(simple_net)\n",
        "\n",
        "old_mod = mod\n",
        "\n",
        "with tvm.transform.PassContext(opt_level=4):\n",
        "    with tvm.target.Target(\"llvm\"):\n",
        "        seq = tvm.transform.Sequential(passes=[relay.transform.ToBasicBlockNormalForm()], opt_level=4)\n",
        "        new_mod = seq(mod)\n",
        "\n",
        "assert old_mod.astext() == mod.astext()\n",
        "assert old_mod.astext() != new_mod.astext()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "rY4-SDNzPJKr"
      },
      "source": [
        "## Bug 10"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 180
        },
        "id": "61C-iamGPM0F",
        "outputId": "52471983-3df0-417d-f4bf-d4a6ccc3808a"
      },
      "outputs": [
        {
          "ename": "TypeError",
          "evalue": "ignored",
          "output_type": "error",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-2-c6ed2bec5811>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mtvm\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mtir\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mhash\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtir\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mStringImm\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"s\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m: unhashable type: 'StringImm'"
          ]
        }
      ],
      "source": [
        "from tvm import tir\n",
        "hash(tir.StringImm(\"s\"))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "7uprfUlQO5hr"
      },
      "source": [
        "## Bug 11"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "SRXwiXQMO8To"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "import numpy as np\n",
        "from tvm import tir, te\n",
        "\n",
        "n = te.size_var(\"n\")\n",
        "m = te.size_var(\"m\")\n",
        "A = te.placeholder((n, n), name=\"A\", dtype=\"int32\")\n",
        "\n",
        "T = te.compute((m, m), lambda i, j: A[i][j])\n",
        "s = te.create_schedule(T.op)\n",
        "ir_m = tvm.lower(s, [A, T])\n",
        "\n",
        "\n",
        "inputs = [tvm.nd.array(np.random.uniform(0, 100, size=(32, 32)).astype(\"int32\"))]\n",
        "output = tvm.nd.empty((32, 32), \"int32\")\n",
        "\n",
        "with tvm.transform.PassContext(opt_level=4):\n",
        "    opt = tvm.transform.Sequential(\n",
        "        [tir.transform.DecorateDeviceScope()]\n",
        "    )\n",
        "    mod = opt(ir_m)\n",
        "\n",
        "opt_execute = tvm.build(mod, [*inputs, output], tvm.target.Target(\"llvm\"))\n",
        "opt_execute(*[inputs[0], output])"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_vLp_FEgOrN3"
      },
      "source": [
        "## Bug 12"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 731
        },
        "id": "SwIPQpt-O3W_",
        "outputId": "75c126af-0b23-4dad-c6e6-14e2e3ffc7f0"
      },
      "outputs": [
        {
          "ename": "TVMError",
          "evalue": "ignored",
          "output_type": "error",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mTVMError\u001b[0m                                  Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-1-e2b9a230cad8>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mtvm\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mtir\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mtvm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbuild\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtir\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPrimFunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtir\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mEvaluate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtir\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mret\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtir\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconst\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/tvm/driver/build_module.py\u001b[0m in \u001b[0;36mbuild\u001b[0;34m(inputs, args, target, target_host, name, binds)\u001b[0m\n\u001b[1;32m    466\u001b[0m     \u001b[0mdevice_modules\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    467\u001b[0m     \u001b[0;32mfor\u001b[0m \u001b[0mtar\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minput_mod\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mtarget_input_mod\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 468\u001b[0;31m         \u001b[0mmod_host\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmdev\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_build_for_device\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput_mod\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtar\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtarget_host\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    469\u001b[0m         \u001b[0mmod_host_all\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmod_host\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    470\u001b[0m         \u001b[0mdevice_modules\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmdev\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/tvm/driver/build_module.py\u001b[0m in \u001b[0;36m_build_for_device\u001b[0;34m(input_mod, target, target_host)\u001b[0m\n\u001b[1;32m    290\u001b[0m         \u001b[0mtvm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtir\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtransform\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mSplitHostDevice\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    291\u001b[0m     ]\n\u001b[0;32m--> 292\u001b[0;31m     \u001b[0mmod_mixed\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtvm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtransform\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mSequential\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mopt_mixed\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmod_mixed\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    293\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    294\u001b[0m     \u001b[0;31m# device optimizations\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/tvm/ir/transform.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, mod)\u001b[0m\n\u001b[1;32m    125\u001b[0m             \u001b[0mThe\u001b[0m \u001b[0mupdated\u001b[0m \u001b[0mmodule\u001b[0m \u001b[0mafter\u001b[0m \u001b[0mapplying\u001b[0m \u001b[0mthis\u001b[0m \u001b[0;32mpass\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    126\u001b[0m         \"\"\"\n\u001b[0;32m--> 127\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0m_ffi_transform_api\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mRunPass\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmod\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    128\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    129\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./packed_func.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.PackedFuncBase.__call__\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./packed_func.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.FuncCall\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./packed_func.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.FuncCall3\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./base.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.CALL\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;31mTVMError\u001b[0m: Traceback (most recent call last):\n  7: TVMFuncCall\n  6: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::runtime::TypedPackedFunc<tvm::IRModule (tvm::transform::Pass, tvm::IRModule)>::AssignTypedLambda<tvm::transform::{lambda(tvm::transform::Pass, tvm::IRModule)#10}>(tvm::transform::{lambda(tvm::transform::Pass, tvm::IRModule)#10}, std::string)::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)\n  5: tvm::transform::Pass::operator()(tvm::IRModule) const\n  4: tvm::transform::SequentialNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const\n  3: tvm::transform::Pass::operator()(tvm::IRModule, tvm::transform::PassContext const&) const\n  2: tvm::transform::ModulePassNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const\n  1: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::runtime::TypedPackedFunc<tvm::IRModule (tvm::IRModule, tvm::transform::PassContext)>::AssignTypedLambda<tvm::tir::transform::MakePackedAPI(int)::{lambda(tvm::IRModule, tvm::transform::PassContext)#1}>(tvm::tir::transform::MakePackedAPI(int)::{lambda(tvm::IRModule, tvm::transform::PassContext)#1})::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)\n  0: tvm::tir::MakePackedAPI(tvm::tir::PrimFunc&&, int)\n  File \"/workspace/tvm/src/tir/transforms/make_packed_api.cc\", line 272\nTVMError: Not all Vars are passed in api_args:  'out_ret_value'  'out_ret_tcode'  is not bound to any variables"
          ]
        }
      ],
      "source": [
        "import tvm\n",
        "from tvm import tir\n",
        "\n",
        "tvm.build(tir.PrimFunc([], tir.Evaluate(tir.ret(tir.const(0)))))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "LLlRhUigOZLo"
      },
      "source": [
        "## Bug 13"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "-H8zlrHeOlIU"
      },
      "outputs": [],
      "source": [
        "from tvm import tir\n",
        "tir.Var(name=1, dtype='int')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "eJwEHgTXOKFt"
      },
      "source": [
        "## Bug 14"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 323
        },
        "id": "RDMuvTRWOTGq",
        "outputId": "d1e85ebd-8557-4f2b-f620-57dcf9c1b7ce"
      },
      "outputs": [
        {
          "ename": "ValueError",
          "evalue": "ignored",
          "output_type": "error",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-1-eab4a163d524>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mtvm\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mtir\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0mtir\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconst\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtir\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconst\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/tvm/tir/expr.py\u001b[0m in \u001b[0;36m__bool__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    176\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    177\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m__bool__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 178\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__nonzero__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    179\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    180\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mequal\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mspan\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/tvm/tir/expr.py\u001b[0m in \u001b[0;36m__nonzero__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    171\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m__nonzero__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    172\u001b[0m         raise ValueError(\n\u001b[0;32m--> 173\u001b[0;31m             \u001b[0;34m\"Cannot use and / or / not operator to Expr, hint: \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    174\u001b[0m             \u001b[0;34m+\u001b[0m \u001b[0;34m\"use tvm.tir.all / tvm.tir.any instead\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    175\u001b[0m         )\n",
            "\u001b[0;31mValueError\u001b[0m: Cannot use and / or / not operator to Expr, hint: use tvm.tir.all / tvm.tir.any instead"
          ]
        }
      ],
      "source": [
        "from tvm import tir\n",
        "print({tir.const(1), tir.const(True)})"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "T_k5PHJVLrIq"
      },
      "source": [
        "## Bug 15 & Bug 16"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "D7Zhj6fjLx_d"
      },
      "outputs": [],
      "source": [
        "from tvm import tir\n",
        "import tvm\n",
        "\n",
        "zero = tir.const(0)\n",
        "nop = tir.Evaluate(zero)\n",
        "v = tir.Var(\"i1\", \"int32\")\n",
        "for_stmt = tir.For(v, zero, zero, tir.ForKind.SERIAL, nop)\n",
        "load = tir.Evaluate(tir.Load(\"int32\", v, zero))\n",
        "seq = tir.SeqStmt([for_stmt, for_stmt, load])\n",
        "func = tir.PrimFunc([], seq)\n",
        "mod = tvm.IRModule({\"main\": func})\n",
        "mod = tir.transform.InjectVirtualThread()(\n",
        "    mod\n",
        ")  # Use pass InjectVirtualThread to invoke ConvertSSA\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "6LuvokylNxT9"
      },
      "outputs": [],
      "source": [
        "from tvm import tir\n",
        "import tvm\n",
        "\n",
        "zero = tir.const(0)\n",
        "nop = tir.Evaluate(zero)\n",
        "v = tir.Var(\"i1\", \"int32\")\n",
        "for_stmt = tir.For(v, zero, zero, tir.ForKind.SERIAL, nop)\n",
        "store = tir.Store(v, zero, zero)\n",
        "seq = tir.SeqStmt([for_stmt, for_stmt, store])\n",
        "func = tir.PrimFunc([], seq)\n",
        "mod = tvm.IRModule({\"main\": func})\n",
        "mod = tir.transform.InjectVirtualThread()(\n",
        "    mod\n",
        ")  # Use pass InjectVirtualThread to invoke ConvertSSA\n",
        "\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vHgRcAGxKb_Z"
      },
      "source": [
        "## Bug 17 & Bug 18"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 571
        },
        "id": "_Qfx3WLUKu7h",
        "outputId": "6b7d617b-8d56-452c-9635-46a79559e3cb"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Array\n"
          ]
        },
        {
          "ename": "TypeError",
          "evalue": "ignored",
          "output_type": "error",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-1-7d25a96115ec>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0marray\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtvm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mruntime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconvert\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtype_key\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtest_key\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/tvm/runtime/object.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m     61\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     62\u001b[0m         \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 63\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0m_ffi_node_api\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mNodeGetAttr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     64\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0mAttributeError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     65\u001b[0m             \u001b[0;32mraise\u001b[0m \u001b[0mAttributeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"%s has no attribute %s\"\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./packed_func.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.PackedFuncBase.__call__\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./packed_func.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.FuncCall\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./packed_func.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.FuncCall3\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./base.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.CALL\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;31mTypeError\u001b[0m: Traceback (most recent call last):\n  3: TVMFuncCall\n  2: _ZNSt17_Function_handlerI\n  1: tvm::NodeGetAttr(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)\n  0: tvm::ReflectionVTable::GetAttr(tvm::runtime::Object*, tvm::runtime::String const&) const\n  File \"/workspace/tvm/include/tvm/node/reflection.h\", line 390\nTypeError: Array is not registered via TVM_REGISTER_NODE_TYPE"
          ]
        }
      ],
      "source": [
        "import tvm\n",
        "array = tvm.runtime.convert([1, 2, 3])\n",
        "print(array.type_key)\n",
        "print(array.test_key)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 571
        },
        "id": "Ay4-VRxfLaUt",
        "outputId": "6b8f5d6d-7de1-4572-9ded-45423f136abb"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Map\n"
          ]
        },
        {
          "ename": "TypeError",
          "evalue": "ignored",
          "output_type": "error",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-2-4685d7fe53f4>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0mamap\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtvm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mruntime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconvert\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      6\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mamap\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtype_key\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mamap\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtest_key\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/tvm/runtime/object.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m     61\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     62\u001b[0m         \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 63\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0m_ffi_node_api\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mNodeGetAttr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     64\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0mAttributeError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     65\u001b[0m             \u001b[0;32mraise\u001b[0m \u001b[0mAttributeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"%s has no attribute %s\"\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./packed_func.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.PackedFuncBase.__call__\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./packed_func.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.FuncCall\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./packed_func.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.FuncCall3\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./base.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.CALL\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;31mTypeError\u001b[0m: Traceback (most recent call last):\n  3: TVMFuncCall\n  2: _ZNSt17_Function_handlerI\n  1: tvm::NodeGetAttr(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)\n  0: tvm::ReflectionVTable::GetAttr(tvm::runtime::Object*, tvm::runtime::String const&) const\n  File \"/workspace/tvm/include/tvm/node/reflection.h\", line 390\nTypeError: Map is not registered via TVM_REGISTER_NODE_TYPE"
          ]
        }
      ],
      "source": [
        "import tvm\n",
        "from tvm import te\n",
        "a = te.var(\"a\")\n",
        "b = te.var(\"b\")\n",
        "amap = tvm.runtime.convert({a: 2, b: 3})\n",
        "print(amap.type_key)\n",
        "print(amap.test_key)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "OVPgrXTgKP67"
      },
      "source": [
        "## Bug 19"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "_GCxO8q3KTHK"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "from tvm import tir\n",
        "\n",
        "var = tir.Var('a',dtype='int32')\n",
        "buf = tir.decl_buffer((1,), name='buf')\n",
        "buf_load = tir.expr.BufferLoad(buffer=buf, indices=tvm.runtime.convert([0]))\n",
        "buf_load_stmt = tir.stmt.Evaluate(buf_load)\n",
        "for_loop = tir.stmt.For(loop_var=var, kind=1, min_val=1, extent=buf_load, body=buf_load_stmt)\n",
        "buf_func = tir.PrimFunc(params={}, body=for_loop)\n",
        "\n",
        "tvm.lower(buf_func)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "M0ETPBbhQlIe"
      },
      "source": [
        "## Bug 20 & Bug 21 & Bug 22"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "w91gVfbU4Ms1",
        "outputId": "8afd6513-1a37-491b-908e-a03a0ac66586"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Elapsed time by API-Misuse case: 0.22153639793395996\n",
            "Elapsed time by correct case: 0.18967914581298828\n"
          ]
        }
      ],
      "source": [
        "# API Misuse in 3 of previous tutorials (bring_your_own_datatypes.py, from_keras.py, from_onnx.py )\n",
        "# We only show one motivating example here.\n",
        "\n",
        "import tvm\n",
        "import tvm.relay as relay\n",
        "from tvm.relay import testing\n",
        "from tvm import IRModule\n",
        "import time\n",
        "\n",
        "shape = (1, 3, 100, 100)\n",
        "\n",
        "def example():\n",
        "    return testing.squeezenet.get_workload(batch_size=1, num_classes=100, image_shape=shape[1:], dtype='float32')\n",
        "    data = relay.var(\"data\", relay.TensorType(shape, \"float32\"))\n",
        "    weight = relay.var(\"weight\")\n",
        "    bn_gamma = relay.var(\"bn_gamma\")\n",
        "    bn_beta = relay.var(\"bn_beta\")\n",
        "    bn_mmean = relay.var(\"bn_mean\")\n",
        "    bn_mvar = relay.var(\"bn_var\")\n",
        "\n",
        "    simple_net = relay.nn.conv2d(\n",
        "        data=data, weight=weight, kernel_size=(5, 5), channels=32, padding=(1, 1)\n",
        "    )\n",
        "    simple_net = relay.nn.batch_norm(simple_net, bn_gamma, bn_beta, bn_mmean, bn_mvar)[0]\n",
        "    simple_net = relay.nn.relu(simple_net)\n",
        "    simple_net = relay.Function(relay.analysis.free_vars(simple_net), simple_net)\n",
        "\n",
        "    return testing.create_workload(simple_net)\n",
        "\n",
        "def error_usage(): # Used in previous tutorial\n",
        "    mod, params = example()\n",
        "    target = tvm.target.Target('llvm')\n",
        "    dev = tvm.cpu()\n",
        "    with tvm.transform.PassContext(opt_level=4): \n",
        "        executor = relay.build_module.create_executor(\"vm\", mod, dev, target)\n",
        "    evaluated = executor.evaluate()\n",
        "\n",
        "    t0 = time.time()\n",
        "    tvm_out = evaluated(\n",
        "        tvm.nd.empty(shape=shape, \n",
        "        device=dev, \n",
        "        dtype='float32'), **params)\n",
        "    print(f'Elapsed time by API-Misuse case: {time.time() - t0}')\n",
        "\n",
        "def good_usage(): # After correction.\n",
        "    mod, params = example()\n",
        "    target = tvm.target.Target('llvm')\n",
        "    dev = tvm.cpu()\n",
        "    with tvm.transform.PassContext(opt_level=4): \n",
        "        mod = IRModule.from_expr(relay.build_module.bind_params_by_name(mod[\"main\"], params))\n",
        "        executor = relay.build_module.create_executor(\"vm\", mod, dev, target).evaluate()\n",
        "    t0 = time.time()\n",
        "    tvm_out = executor(\n",
        "        tvm.nd.empty(shape=shape, \n",
        "        device=dev, \n",
        "        dtype='float32'), **params)\n",
        "    print(f'Elapsed time by correct case: {time.time() - t0}')\n",
        "\n",
        "if __name__ == '__main__':\n",
        "    error_usage()\n",
        "    good_usage()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "zqnEknpzQKPD"
      },
      "source": [
        "## Bug 23"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "KG8f5njjYdSH",
        "outputId": "ab3c2764-7bea-4721-c6c3-a6b900091601"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "...100%, 0.47 MB, 1596 KB/s, 0 seconds passed\n"
          ]
        },
        {
          "ename": "TVMError",
          "evalue": "ignored",
          "output_type": "error",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mTVMError\u001b[0m                                  Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-2-318f34753a08>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m     29\u001b[0m \u001b[0mseq\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtvm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtransform\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mSequential\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mrelay\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtransform\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mAnnotateSpans\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrelay\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtransform\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDefuseOps\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     30\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mtvm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtransform\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPassContext\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mopt_level\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 31\u001b[0;31m     \u001b[0mmodule\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mseq\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodule\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/tvm/ir/transform.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, mod)\u001b[0m\n\u001b[1;32m    125\u001b[0m             \u001b[0mThe\u001b[0m \u001b[0mupdated\u001b[0m \u001b[0mmodule\u001b[0m \u001b[0mafter\u001b[0m \u001b[0mapplying\u001b[0m \u001b[0mthis\u001b[0m \u001b[0;32mpass\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    126\u001b[0m         \"\"\"\n\u001b[0;32m--> 127\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0m_ffi_transform_api\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mRunPass\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmod\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    128\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    129\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./packed_func.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.PackedFuncBase.__call__\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./packed_func.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.FuncCall\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./packed_func.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.FuncCall3\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;32mtvm/_ffi/_cython/./base.pxi\u001b[0m in \u001b[0;36mtvm._ffi._cy3.core.CALL\u001b[0;34m()\u001b[0m\n",
            "\u001b[0;31mTVMError\u001b[0m: Traceback (most recent call last):\n  33: TVMFuncCall\n  32: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::runtime::TypedPackedFunc<tvm::IRModule (tvm::transform::Pass, tvm::IRModule)>::AssignTypedLambda<tvm::transform::{lambda(tvm::transform::Pass, tvm::IRModule)#10}>(tvm::transform::{lambda(tvm::transform::Pass, tvm::IRModule)#10}, std::string)::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)\n  31: tvm::transform::Pass::operator()(tvm::IRModule) const\n  30: tvm::transform::SequentialNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const\n  29: tvm::transform::Pass::operator()(tvm::IRModule, tvm::transform::PassContext const&) const\n  28: tvm::relay::transform::FunctionPassNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const\n  27: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::runtime::TypedPackedFunc<tvm::relay::Function (tvm::relay::Function, tvm::IRModule, tvm::transform::PassContext)>::AssignTypedLambda<tvm::relay::transform::DefuseOps()::{lambda(tvm::relay::Function, tvm::IRModule, tvm::transform::PassContext)#1}>(tvm::relay::transform::DefuseOps()::{lambda(tvm::relay::Function, tvm::IRModule, tvm::transform::PassContext)#1})::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)\n  26: tvm::relay::DefuseOps(tvm::RelayExpr const&)\n  25: tvm::relay::ExprMutator::VisitExpr(tvm::RelayExpr const&)\n  24: tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)\n  23: _ZZN3tvm5relay11ExprFunc\n  22: tvm::relay::ExprMutator::VisitExpr_(tvm::relay::FunctionNode const*)\n  21: tvm::relay::ExprMutator::VisitExpr(tvm::RelayExpr const&)\n  20: tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)\n  19: _ZZN3tvm5relay11ExprFunc\n  18: tvm::relay::DefuseOpsMutator::VisitExpr_(tvm::relay::CallNode const*)\n  17: tvm::relay::ExprMutator::VisitExpr_(tvm::relay::CallNode const*)\n  16: tvm::relay::ExprMutator::VisitExpr(tvm::RelayExpr const&)\n  15: tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)\n  14: _ZZN3tvm5relay11ExprFunc\n  13: tvm::relay::DefuseOpsMutator::VisitExpr_(tvm::relay::CallNode const*)\n  12: tvm::relay::ExprMutator::VisitExpr_(tvm::relay::CallNode const*)\n  11: tvm::relay::ExprMutator::VisitExpr(tvm::RelayExpr const&)\n  10: tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)\n  9: _ZZN3tvm5relay11ExprFunc\n  8: tvm::relay::DefuseOpsMutator::VisitExpr_(tvm::relay::CallNode const*)\n  7: tvm::relay::ExprMutator::VisitExpr(tvm::RelayExpr const&)\n  6: tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)\n  5: _ZZN3tvm5relay11ExprFunc\n  4: tvm::relay::ExprMutator::VisitExpr_(tvm::relay::CallNode const*)\n  3: tvm::relay::ExprMutator::VisitExpr(tvm::RelayExpr const&)\n  2: tvm::relay::ExprFunctor<tvm::RelayExpr (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)\n  1: _ZZN3tvm5relay11ExprFunc\n  0: tvm::relay::DefuseOpsMutator::FuncBodyMutator::VisitExpr_(tvm::relay::VarNode const*)\n  File \"/workspace/tvm/src/relay/transforms/defuse_ops.cc\", line 51\nTVMError: \n---------------------------------------------------------------\nAn error occurred during the execution of TVM.\nFor more information, please see: https://tvm.apache.org/docs/errors.html\n---------------------------------------------------------------\n  Check failed: (id >= 0 && size_t(id) < args_.size()) is false: "
          ]
        }
      ],
      "source": [
        "# Imcompatible passes (but actually independent) introduced by inconsistency.\n",
        "\n",
        "import tvm\n",
        "import tvm.testing\n",
        "\n",
        "from tvm import relay\n",
        "from tvm.relay import testing\n",
        "\n",
        "data = relay.var(\"data\", relay.TensorType((1, 3, 64, 64), \"float32\"))\n",
        "weight = relay.var(\"weight\")\n",
        "\n",
        "bn_gamma = relay.var(\"bn_gamma\")\n",
        "bn_beta = relay.var(\"bn_beta\")\n",
        "bn_mmean = relay.var(\"bn_mean\")\n",
        "bn_mvar = relay.var(\"bn_var\")\n",
        "\n",
        "simple_net = relay.nn.conv2d(\n",
        "    data=data, weight=weight, kernel_size=(3, 3), channels=3, padding=(1, 1)\n",
        ")\n",
        "simple_net = relay.nn.batch_norm(simple_net, bn_gamma, bn_beta, bn_mmean, bn_mvar)[0]\n",
        "simple_net = relay.Function(relay.analysis.free_vars(simple_net), simple_net)\n",
        "\n",
        "module, params = testing.create_workload(simple_net)\n",
        "\n",
        "# Apply some simple passes to legalize the IR.\n",
        "with tvm.transform.PassContext(opt_level=0):\n",
        "    module, params = relay.optimize(module, tvm.testing.enabled_targets()[0][0], params)\n",
        "\n",
        "seq = tvm.transform.Sequential([relay.transform.AnnotateSpans(), relay.transform.DefuseOps()])\n",
        "with tvm.transform.PassContext(opt_level=3):\n",
        "    module = seq(module)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "90QS15V7TAxG"
      },
      "source": [
        "## Bug 24 & Bug 25 & Bug 26"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "duHYfXEAW9hR"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "tvm.tir.expr.Call(None, None, None, None)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "dDDIeqYXTH32"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "tvm.tir.generic.add(None, None)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "Hc49mmySXsCE"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "tvm.tir.stmt.Allocate(None, None, None, None, None, None)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "os4WXkaVSM9I"
      },
      "source": [
        "## Bug 27"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "74EZ1vMSQo3z",
        "outputId": "0589e481-0abf-4c55-e204-0155b2af662b"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Linux 26e8f5ac1921 5.4.104+ #1 SMP Sat Jun 5 09:50:34 PDT 2021 x86_64 x86_64 x86_64 GNU/Linux\n"
          ]
        }
      ],
      "source": [
        "# CuDNN context error. The script ended with a hang and segfault. \n",
        "# This bug is reproducible on CentOS 7. Other platform might not be able to reproduce this.\n",
        "\n",
        "\n",
        "!uname -a # Linux of Google Colab is not CentOS 7 and cannot reproduce this bug.\n",
        "\n",
        "# The output of this program on CentOS 7\n",
        "\"\"\"\n",
        "[03:09:31] ../src/runtime/contrib/cudnn/conv_forward.cc:245:    CUDNN Found 8 fwd algorithms, choosing CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_GEMM\n",
        "[03:09:31] ../src/runtime/contrib/cudnn/conv_forward.cc:248:            0) CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_GEMM - time: 0.06144 ms, Memory: 0\n",
        "[03:09:31] ../src/runtime/contrib/cudnn/conv_forward.cc:248:            1) CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_PRECOMP_GEMM - time: 0.104448 ms, Memory: 304000\n",
        "[03:09:31] ../src/runtime/contrib/cudnn/conv_forward.cc:248:            2) CUDNN_CONVOLUTION_FWD_ALGO_GEMM - time: 0.110592 ms, Memory: 5419008\n",
        "[03:09:31] ../src/runtime/contrib/cudnn/conv_forward.cc:248:            3) CUDNN_CONVOLUTION_FWD_ALGO_WINOGRAD - time: 0.146432 ms, Memory: 18176\n",
        "[03:09:31] ../src/runtime/contrib/cudnn/conv_forward.cc:248:            4) CUDNN_CONVOLUTION_FWD_ALGO_FFT - time: 0.916384 ms, Memory: 26949312\n",
        "[03:09:31] ../src/runtime/contrib/cudnn/conv_forward.cc:248:            5) CUDNN_CONVOLUTION_FWD_ALGO_FFT_TILING - time: 1.10106 ms, Memory: 374272\n",
        "[03:09:31] ../src/runtime/contrib/cudnn/conv_forward.cc:248:            6) CUDNN_CONVOLUTION_FWD_ALGO_WINOGRAD_NONFUSED - time: 1.79712 ms, Memory: 137288448\n",
        "[03:09:31] ../src/runtime/contrib/cudnn/conv_forward.cc:248:            7) CUDNN_CONVOLUTION_FWD_ALGO_DIRECT - time: -1 ms, Memory: 0\n",
        "One or more operators have not been tuned. Please tune your model for better performance. Use DEBUG logging level to see more details.\n",
        "[1]    134780 segmentation fault (core dumped)  python3 test.py\n",
        "\"\"\" \n",
        "\n",
        "content = \"\"\"\n",
        "import tvm\n",
        "import tvm.relay as relay\n",
        "import numpy as np\n",
        "from tvm.relay import testing\n",
        "\n",
        "def example():\n",
        "    out_channels = 16\n",
        "    batch_size = 1\n",
        "\n",
        "    data = relay.var(\"data\", relay.TensorType((batch_size, 3, 224, 224), \"float32\"))\n",
        "    weight = relay.var(\"weight\")\n",
        "    bn_gamma = relay.var(\"bn_gamma\")\n",
        "    bn_beta = relay.var(\"bn_beta\")\n",
        "    bn_mmean = relay.var(\"bn_mean\")\n",
        "    bn_mvar = relay.var(\"bn_var\")\n",
        "\n",
        "    simple_net = relay.nn.conv2d(\n",
        "        data=data, weight=weight, kernel_size=(3, 3), channels=out_channels, padding=(1, 1)\n",
        "    )\n",
        "    simple_net = relay.nn.batch_norm(simple_net, bn_gamma, bn_beta, bn_mmean, bn_mvar)[0]\n",
        "    simple_net = relay.nn.relu(simple_net)\n",
        "    simple_net = relay.Function(relay.analysis.free_vars(simple_net), simple_net)\n",
        "\n",
        "    return testing.create_workload(simple_net)\n",
        "\n",
        "def func():\n",
        "    data = np.zeros((1, 3, 224, 224))\n",
        "    mod, params = example()\n",
        "    target = tvm.target.Target('cuda -libs=cudnn')\n",
        "    dev = tvm.cuda()\n",
        "    with tvm.transform.PassContext(opt_level=3):\n",
        "        executor = relay.build_module.create_executor(\"graph\", mod, dev, target)\n",
        "\n",
        "    tvm_out = executor.evaluate()(tvm.nd.array(data.astype('float32')), **params)\n",
        "\"\"\"\n",
        "\n",
        "with open('test.py', 'w') as f:\n",
        "    f.write(content)\n",
        "\n",
        "!python3 test.py"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Vq5MgjhCSM6v"
      },
      "source": [
        "## Bug 28 & 29\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "CJrwR4XCUs6S",
        "outputId": "986bf120-8761-45a8-d0ec-1321a0ad52a3"
      },
      "outputs": [
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "One or more operators have not been tuned. Please tune your model for better performance. Use DEBUG logging level to see more details.\n",
            "Cannot find config for target=cuda -keys=cuda,gpu -max_num_threads=1024 -thread_warp_size=32, workload=('conv2d_nchw.cuda', ('TENSOR', (any_dim, 3, 224, 224), 'float32'), ('TENSOR', (32, 3, 3, 3), 'float32'), (1, 1), (1, 1, 1, 1), (1, 1), 'float32'). A fallback configuration is used, which may bring great performance regression.\n"
          ]
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Running batch size = 0\n",
            "Running batch size = 1\n",
            "Running batch size = 2\n",
            "Running batch size = 3\n",
            "Running batch size = 4\n",
            "Running batch size = 5\n",
            "Running batch size = 6\n",
            "Running batch size = 7\n",
            "Running batch size = 8\n",
            "Running batch size = 9\n",
            "Running batch size = 10\n",
            "Running batch size = 11\n",
            "Running batch size = 12\n",
            "Running batch size = 13\n",
            "Running batch size = 14\n",
            "Running batch size = 15\n",
            "Running batch size = 16\n",
            "Running batch size = 17\n",
            "Running batch size = 18\n",
            "Running batch size = 19\n",
            "Running batch size = 20\n",
            "Running batch size = 21\n",
            "Running batch size = 22\n",
            "Running batch size = 23\n",
            "Running batch size = 24\n",
            "Running batch size = 25\n",
            "Running batch size = 26\n",
            "Running batch size = 27\n",
            "Running batch size = 28\n",
            "Running batch size = 29\n",
            "Running batch size = 30\n",
            "Running batch size = 31\n",
            "Running batch size = 32\n",
            "Running batch size = 33\n",
            "Running batch size = 34\n",
            "Running batch size = 35\n",
            "Running batch size = 36\n",
            "Running batch size = 37\n",
            "Running batch size = 38\n",
            "Running batch size = 39\n",
            "Running batch size = 40\n",
            "Running batch size = 41\n",
            "Running batch size = 42\n",
            "Running batch size = 43\n",
            "Running batch size = 44\n",
            "Running batch size = 45\n",
            "Running batch size = 46\n",
            "Running batch size = 47\n",
            "Running batch size = 48\n",
            "Running batch size = 49\n",
            "Running batch size = 50\n",
            "Running batch size = 51\n",
            "Running batch size = 52\n",
            "Running batch size = 53\n",
            "Running batch size = 54\n",
            "Running batch size = 55\n",
            "Running batch size = 56\n",
            "Running batch size = 57\n"
          ]
        }
      ],
      "source": [
        "# There are 2 bugs here. \n",
        "# 1. One is about OOM.\n",
        "# 2. Another is the incorrect exception. (The exception should be OOM not \"device type = 0\")\n",
        "\n",
        "import tvm\n",
        "import tvm.relay as relay\n",
        "import numpy as np\n",
        "from tvm.relay import testing\n",
        "\n",
        "def example():\n",
        "    out_channels = 32\n",
        "\n",
        "    data = relay.var(\"data\", relay.TensorType((relay.Any(), 3, 224, 224), \"float32\"))\n",
        "    weight = relay.var(\"weight\")\n",
        "    bn_gamma = relay.var(\"bn_gamma\")\n",
        "    bn_beta = relay.var(\"bn_beta\")\n",
        "    bn_mmean = relay.var(\"bn_mean\")\n",
        "    bn_mvar = relay.var(\"bn_var\")\n",
        "\n",
        "    simple_net = relay.nn.conv2d(\n",
        "        data=data, weight=weight, kernel_size=(3, 3), channels=out_channels, padding=(1, 1)\n",
        "    )\n",
        "    simple_net = relay.nn.batch_norm(simple_net, bn_gamma, bn_beta, bn_mmean, bn_mvar)[0]\n",
        "    simple_net = relay.nn.relu(simple_net)\n",
        "    simple_net = relay.Function(relay.analysis.free_vars(simple_net), simple_net)\n",
        "\n",
        "    return testing.create_workload(simple_net)\n",
        "\n",
        "if __name__ == '__main__':\n",
        "    mod, params = example()\n",
        "    # compile the model\n",
        "    target = tvm.target.Target('cuda')\n",
        "    dev = tvm.cuda()\n",
        "    with tvm.transform.PassContext(opt_level=3):\n",
        "        executor = relay.build_module.create_executor(\"vm\", mod, dev, target)\n",
        "\n",
        "    for i in range(100):\n",
        "        print(f'Running batch size = {i}')  # Should be OOM error, but a later exception received.\n",
        "        tvm_out = executor.evaluate()(tvm.nd.empty(shape=(i, 3, 224, 224), device=dev, dtype='float32'), **params)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-IXFoOgtSJW0"
      },
      "source": [
        "## Bug 30"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ioDbVeXTYhja",
        "outputId": "94773ee6-fb1e-467a-8c29-88d01c2d458b"
      },
      "outputs": [
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Cannot find config for target=cuda -keys=cuda,gpu -max_num_threads=1024 -thread_warp_size=32, workload=('conv2d_nchw.cuda', ('TENSOR', (any_dim, 3, 128, 128), 'float32'), ('TENSOR', (8, 3, 3, 3), 'float32'), (1, 1), (1, 1, 1, 1), (1, 1), 'float32'). A fallback configuration is used, which may bring great performance regression.\n"
          ]
        }
      ],
      "source": [
        "# We tested tvm across various runtimes (vm, graph, debug, etc.)\n",
        "# We found debug module fails for 0-batch input (viable for other runtime types)\n",
        "# We observed CUDA internal error using cuda-gdb.\n",
        "\n",
        "import tvm\n",
        "import tvm.relay as relay\n",
        "import numpy as np\n",
        "from tvm.relay import testing\n",
        "\n",
        "def example():\n",
        "    data = relay.var(\"data\", relay.TensorType((relay.Any(), 3, 128, 128), \"float32\"))\n",
        "    simple_net = relay.nn.conv2d(\n",
        "        data=data, weight=relay.var(\"weight\"), kernel_size=(3, 3), channels=8, padding=(1, 1)\n",
        "    )\n",
        "    simple_net = relay.Function(relay.analysis.free_vars(simple_net), simple_net)\n",
        "\n",
        "    return testing.create_workload(simple_net)\n",
        "\n",
        "if __name__ == '__main__':\n",
        "    data = np.zeros((0, 3, 128, 128))\n",
        "    mod, params = example()\n",
        "    target = tvm.target.Target('cuda')\n",
        "    dev = tvm.cuda()\n",
        "    with tvm.transform.PassContext(opt_level=2):\n",
        "        executor = relay.build_module.create_executor(\"debug\", mod, dev, target)\n",
        "\n",
        "    tvm_out = executor.evaluate()(tvm.nd.array(data.astype('float32')), **params)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "yxN4msAEbF2_"
      },
      "source": [
        "## Bug 31"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "N2YDNkLJbJlI"
      },
      "outputs": [],
      "source": [
        "from tvm import tir\n",
        "import tvm\n",
        "\n",
        "a = tir.Broadcast(tir.const(1), 2)\n",
        "v = tir.Var('i1', 'int32')\n",
        "stmt = tir.Store(v, a, a, None)\n",
        "func = tir.PrimFunc([v], stmt)\n",
        "tvm.build(func)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "d350EDH_bVyp"
      },
      "source": [
        "## Bug 32"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "TFVjAw6mbYob"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "buf = tvm.tir.buffer.decl_buffer((1,))\n",
        "value = tvm.tir.IntImm('int32', 1)\n",
        "i = tvm.tir.IntImm('int32x1', 1)\n",
        "index = tvm.tir.Shuffle([i, i], [i])\n",
        "s = tvm.tir.Store(buf.data, value, index)\n",
        "f = tvm.tir.PrimFunc({buf.data}, s)\n",
        "tvm.build(f)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "AhGTlYHxbf4g"
      },
      "source": [
        "## Bug 33"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "31QWn6eLbh9g"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "\n",
        "v = tvm.tir.Var('v', 'float32')\n",
        "value = tvm.tir.isnan(v)\n",
        "op = value.op\n",
        "\n",
        "buf = tvm.tir.buffer.decl_buffer((1,))\n",
        "value = tvm.tir.Call('int32', op, [0])\n",
        "s = tvm.tir.Store(buf.data, value, 0)\n",
        "f = tvm.tir.PrimFunc({buf.data}, s)\n",
        "tvm.build(f)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ZRRT_gZKbk6b"
      },
      "source": [
        "## Bug 34"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "HT79vweTbszo"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "from tvm import tir\n",
        "\n",
        "var = tir.Var(name='v', dtype='int32')\n",
        "buf = tir.decl_buffer((1,), name='buf')\n",
        "buf_load = tir.expr.BufferLoad(buffer=buf, indices=tvm.runtime.convert([0]))\n",
        "then_case = tir.Store(buffer_var=var,value=buf_load,index=tvm.runtime.convert(0))\n",
        "for_body = then_case\n",
        "for_stmt = tir.For(loop_var=var, min_val=0, extent=0, kind=1,body=for_body)\n",
        "y = tir.IfThenElse(then_case=then_case,else_case=for_stmt,condition=tvm.runtime.convert(False))\n",
        "f=tir.PrimFunc(body=y,params=[var])\n",
        "\n",
        "mod = tvm.IRModule({'main':f})\n",
        "mod = tir.transform.PlanAndUpdateBufferAllocationLocation()(mod)\n",
        "mod = tir.transform.CompactBufferAllocation()(mod)\n",
        "mod = tir.transform.LowerMatchBuffer()(mod)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "8dUsFrtpbttF"
      },
      "source": [
        "## Bug 35"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 368
        },
        "id": "HVxXveTebx3U",
        "outputId": "dacd27aa-d5b0-4236-ebc6-c15e67daef15"
      },
      "outputs": [
        {
          "ename": "ModuleNotFoundError",
          "evalue": "ignored",
          "output_type": "error",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-4-2533e17feeaa>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mtvm\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mtvm\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mtir\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgetpid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0minput\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'tvm'",
            "",
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0;32m\nNOTE: If your import is failing due to a missing package, you can\nmanually install dependencies using either !pip or !apt.\n\nTo view examples of installing some common dependencies, click the\n\"Open Examples\" button below.\n\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n"
          ]
        }
      ],
      "source": [
        "import tvm\n",
        "from tvm import tir\n",
        "# import os\n",
        "# print(os.getpid())\n",
        "# input()\n",
        "v = tir.Broadcast(0, 8)\n",
        "index = tir.Ramp(72,1,8)\n",
        "buf = tir.buffer.decl_buffer((1, 0))\n",
        "store = tir.Store(buf.data, v, index)\n",
        "loop_var = tir.Var('v', 'int32')\n",
        "for_loop = tir.For(loop_var, 0, 4, tir.ForKind.VECTORIZED, store)\n",
        "f = tir.PrimFunc({buf.data}, for_loop)\n",
        "tvm.build(f)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "HH03-TtCbys8"
      },
      "source": [
        "## Bug 36"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "m7mVz4tib3HE"
      },
      "outputs": [],
      "source": [
        "# This bug happens to Debug Mode\n",
        "import tvm\n",
        "from tvm import ir, tir\n",
        "\n",
        "a = tir.Var(\"a\", \"int32\")\n",
        "iter_var = tir.IterVar(ir.Range(0,1 ), a, 1, \"vthread\")\n",
        "attr_stmt = tir.AttrStmt(iter_var, \"virtual_thread\",tir.op.floormod(tir.ret(tir.IntImm('int32',0)), 3), tir.Evaluate(tir.const(0)))\n",
        "f = tir.PrimFunc({a}, body=attr_stmt)#, buffer_map=buffer_map)\n",
        "mod = tvm.lower(f)\n",
        "tvm.build(mod)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3xi2_Jnqb6NR"
      },
      "source": [
        "## Bug 37"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "0kND6DYub8YP"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "from tvm import tir\n",
        "s_v = tir.Var('buf', 'handle')\n",
        "buf = tir.buffer.decl_buffer((1, 0))\n",
        "store = tir.Store(buf.data, tir.IntImm('int32', 0), 0, tvm.runtime.convert(32))\n",
        "f = tir.PrimFunc({s_v}, store, buffer_map={s_v:buf})\n",
        "tvm.build(f)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5K58iZIkcA5i"
      },
      "source": [
        "## Bug 38"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "TNNWrsRBcCru"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "from tvm import tir\n",
        "\n",
        "v = tir.Var('v', 'int32')\n",
        "s = tir.Select(tir.Cast('bool',v), 150, 1)\n",
        "let_stmt = tir.LetStmt(v, s, tir.Evaluate(v))\n",
        "f = tir.PrimFunc({v},let_stmt)\n",
        "tvm.build(f)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1WcBly3xAc4a"
      },
      "source": [
        "## Bug 39"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "8eMo0kDMAfBo"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "from tvm import tir\n",
        "expr = tir.Div(tir.FloorDiv(tir.Cast('int32', 2.95148e+28), tir.atan(tir.IntImm('int32',1))), tir.FloorMod(303, 32))\n",
        "stmt = tir.Evaluate(expr)\n",
        "func = tir.PrimFunc({},stmt)\n",
        "tvm.build(func)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "77xn9dIo5xrj"
      },
      "source": [
        "## Bug 40"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "KGwxL7WA50u2"
      },
      "outputs": [],
      "source": [
        "import tvm\n",
        "from tvm import tir\n",
        "\n",
        "var = tir.Var('var', 'int32')\n",
        "false_value = tir.Cast('int32', tir.acosh(tir.Cast('float32', var)))\n",
        "value = tir.Select(var > 0, tir.const(0), false_value)\n",
        "let_stmt = tir.LetStmt(var, value, tir.Evaluate(var))\n",
        "f = tir.PrimFunc({}, let_stmt)\n",
        "tvm.build(f)"
      ]
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "collapsed_sections": [
        "-HTdNvvPPmIC",
        "rY4-SDNzPJKr",
        "7uprfUlQO5hr",
        "_vLp_FEgOrN3",
        "LLlRhUigOZLo",
        "eJwEHgTXOKFt",
        "T_k5PHJVLrIq",
        "vHgRcAGxKb_Z",
        "OVPgrXTgKP67",
        "M0ETPBbhQlIe",
        "zqnEknpzQKPD",
        "90QS15V7TAxG",
        "os4WXkaVSM9I",
        "Vq5MgjhCSM6v",
        "-IXFoOgtSJW0",
        "yxN4msAEbF2_",
        "d350EDH_bVyp",
        "AhGTlYHxbf4g",
        "ZRRT_gZKbk6b",
        "8dUsFrtpbttF",
        "HH03-TtCbys8",
        "3xi2_Jnqb6NR",
        "5K58iZIkcA5i",
        "1WcBly3xAc4a",
        "77xn9dIo5xrj"
      ],
      "name": "Tzer_bugs.ipynb",
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
